//
//  MovieTableViewCell.m
//  LPSNews
//
//  Created by luffy on 14-10-23.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation MovieTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];
        
        UIImageView * movieImageView = [[UIImageView alloc] init];
        UILabel * movieTitle = [[UILabel alloc] init];
        UILabel * movieAccessibilityLabel = [[UILabel alloc] init];
        UIView * techBottomLine = [[UIView alloc] init];
        
        self.movImageView = movieImageView;
        self.titleLabel = movieTitle;
        self.movieAccessibilityLabel = movieAccessibilityLabel;
        self.techBottomLine = techBottomLine;
        
        [self addSubview:movieImageView];
        [self addSubview:movieTitle];
        [self addSubview:movieAccessibilityLabel];
        [self addSubview:techBottomLine];
        
        [movieAccessibilityLabel release];
        [movieImageView release];
        [movieTitle release];
        [techBottomLine release];

    }
    return self;
}
- (void)setMovie:(MovieModel *)movie
{
    [self.movImageView sd_setImageWithURL:[NSURL URLWithString:movie.imgsrc] placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
    
    // 判断是否为第一个ROW
    if (movie.number == 0) {
        // 第一个大图
        CGSize tempsize = CGSizeMake(320, 185);
        self.movImageView.frame = (CGRect){CGPointZero,tempsize};
        
        // 大图的文字
        self.titleLabel.text = movie.title;
        self.titleLabel.frame = CGRectMake(14,CGRectGetMaxY(self.movImageView.frame) + 1, [UIScreen mainScreen].bounds.size.width -20, 25);
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
    }else{
        if (movie.imgType == 1) {
            // 主标题
            self.titleLabel.text = movie.title;
            self.titleLabel.font = [UIFont systemFontOfSize:13];
            self.titleLabel.frame = CGRectMake(10, 0, 300, 20);
            // 左面图片
            CGPoint tempoint = CGPointMake(10, 25);
            CGSize size = CGSizeMake(300, 100);
            self.movImageView.frame = (CGRect){tempoint,size};
            self.movImageView.contentMode = UIViewContentModeScaleAspectFill;
            self.movImageView.clipsToBounds = YES;
            // 内容标题
            self.movieAccessibilityLabel.text = movie.digest;
            self.movieAccessibilityLabel.frame = CGRectMake(10, CGRectGetMaxY(self.movImageView.frame)-5 , 300, 40);
            self.movieAccessibilityLabel.font = [UIFont systemFontOfSize:12.5         ];
            self.movieAccessibilityLabel.textColor = [UIColor darkGrayColor];
            self.movieAccessibilityLabel.numberOfLines = 0;
            self.movieAccessibilityLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
            // 底部的线
            self.techBottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.movImageView.frame)+ 29.75, [UIScreen mainScreen].bounds.size.width, 0.75);
            
        }else{
            
            // 左面图片
            CGPoint tempoint = CGPointMake(10, 9.75);
            CGSize size = CGSizeMake(88.64, 65);
            self.movImageView.frame = (CGRect){tempoint,size};
            self.movImageView.contentMode = UIViewContentModeScaleAspectFill;
            self.movImageView.clipsToBounds = YES;
            
            // 主标题
            self.titleLabel.text = movie.title;
            self.titleLabel.font = [UIFont systemFontOfSize:14.5];
            self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.movImageView.frame) + 10, 10, [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.movImageView.frame), 20);
            
            // 内容标题
            self.movieAccessibilityLabel.text = movie.digest;
            self.movieAccessibilityLabel.frame = CGRectMake(CGRectGetMaxX(self.movImageView.frame) + 10, CGRectGetMaxY(self.titleLabel.frame), [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.movImageView.frame) -10 ,50);
            self.movieAccessibilityLabel.font = [UIFont systemFontOfSize:12.5         ];
            self.movieAccessibilityLabel.textColor = [UIColor darkGrayColor];
            self.movieAccessibilityLabel.numberOfLines = 0;
            self.movieAccessibilityLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
            
            // 底部的线
            self.techBottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.movImageView.frame)+ 9.75, [UIScreen mainScreen].bounds.size.width, 0.75);
        }
    }
    
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
